package com.chuyu.jzwboa.base;

import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.View;

import com.hannesdorfmann.mosby3.mvp.MvpActivity;
import com.hannesdorfmann.mosby3.mvp.MvpPresenter;
import com.hannesdorfmann.mosby3.mvp.MvpView;

import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * @author 杨仕俊
 * @descritpion mvp的baseactivity
 * Created by wo on 2017/12/14.
 */

public abstract class MVPBaseActivity<V extends MvpView, P extends MvpPresenter<V>>
        extends MvpActivity <V , P > implements MvpView{

    private Unbinder bind;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setLayoutStatusBar();
        super.onCreate(savedInstanceState);
        setContentView(initContent());
        bind = ButterKnife.bind(this);
        initView();
        initData();

    }

    /**
     * 设置状态栏透明
     */
    private void setLayoutStatusBar() {
        if (Build.VERSION.SDK_INT >= 21) {
            View decorView = getWindow().getDecorView();
            int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
            decorView.setSystemUiVisibility(option);
            getWindow().setStatusBarColor(Color.TRANSPARENT);
        }

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            this.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
        }
    }

    /**
     * 布局xml
     * @return
     */
    protected abstract int initContent();

    /**
     * 初始化控件
     */
    protected abstract void initView();

    /**
     * 初始化数据
     */
    protected abstract void initData();

    //取消订阅 、绑定
    @Override
    protected void onDestroy() {
        bind.unbind();
        super.onDestroy();
    }
}
